<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layout/masterLayout.xhtml">
	<ui:define name="content">
		<h:panelGroup id="questionBoard">
			<h:form rendered="#{questionBean.state == 'DEFINING_QUESTION'}">
				<h:panelGrid columns="2">
					<h:outputText value="Question" />
					<h:inputTextarea value="#{questionBean.questionField}" rows="10" cols="40">
						<f:validator validatorId="instructorExclusiveValidator" />
					</h:inputTextarea>

					<h:commandButton value="Define Question"
						action="#{questionBean.defineQuestion}" />
				</h:panelGrid>
			</h:form>

			<h:form rendered="#{questionBean.state == 'ANSWERING_QUESTION'}">
				<h:panelGrid columns="2">
					<h:outputText value="Question" />
					<h:outputText value="#{questionBean.question.text}" styleClass="preformatted" />

					<h:outputText value="Answer" />
					<h:inputTextarea value="#{answerBean.answer}"  rows="10" cols="40"/>

					<h:commandButton value="Answer"
						action="#{answerBean.publishAnswer}" />
					<h:panelGroup />
				</h:panelGrid>
			</h:form>
			<h:panelGroup id="soFar"
				rendered="#{questionBean.state == 'ANSWERING_QUESTION'}">
				<hr />
				<h:outputText
					value="#{questionBean.question.numOfAnswered} answers so far" />
				<h:form rendered="#{userBean.instructor}">
					<h:commandButton value="Finish"
						action="#{questionBean.finishAnswers}" />
				</h:form>
			</h:panelGroup>

			<h:form rendered="#{questionBean.state == 'EVALUATING_ANSWERS'}">
				<h:outputText value="#{questionBean.question.text}" styleClass="preformatted" />
				<h:dataTable value="#{questionBean.question.answerList}" var="v"
					border="1" rows="3" >
					<h:column>
						<f:facet name="header">Evaluation</f:facet>
						<h:inputText value="#{v.evaluation}" />
					</h:column>
					<h:column width="100%">
						<f:facet name="header">Answer</f:facet>
						<h:outputText value="#{v.text}" styleClass="preformatted"/>
					</h:column>
				</h:dataTable>
				<h:commandButton value="Finish Evaluation" rendered="#{userBean.instructor}"
					action="#{questionBean.finishEvaluation}" />
			</h:form>

			<h:form>
				<p:poll interval="8" listener="#{postBean.refresh()}" update=":soFar" />
			</h:form>
		</h:panelGroup>
	</ui:define>
</ui:composition>
</html>